import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:何人亮
 * Date:2024-08-04
 * 21:57
 */
public class Teast {
    public static void main(String[] args) {
        MyQueue myQueue=new MyQueue();
        myQueue.push(1);
        myQueue.push(2);
        myQueue.peek();
        myQueue.pop();
    }
}
class MyQueue {
    Stack<Integer> stack1;
    Stack<Integer> stack2;
    public MyQueue() {
        stack1=new Stack<>();
        stack2=new Stack<>();
    }

    public void push(int x) {
        if(!stack1.isEmpty()) {
            stack1.push(x);
        }else if(!stack2.isEmpty()){
            int size=stack2.size();
            for (int i = 0; i < size; i++) {
                 int val=stack2.pop();
                 stack1.push(val);
            }
            stack1.push(x);
        }else{
            stack1.push(x);
        }
    }

    public int pop() {
        if(empty()){
            return -1;
        }
        if(stack2.isEmpty()){
            int size=stack1.size();
            for (int i = 0; i < size; i++) {
                stack2.push(stack1.pop());
            }
            return stack2.pop();
        }else{
            return stack2.pop();
        }
    }

    public int peek() {
        if(empty()){
            return -1;
        }
        if(stack2.isEmpty()){
            int size=stack1.size();
            for (int i = 0; i < size; i++) {
                stack2.push(stack1.pop());
            }
            return stack2.peek();
        }else{
            return stack2.peek();
        }
    }

    public boolean empty() {
        return stack1.isEmpty()&&stack2.isEmpty();
    }
}
